package com.ruoyi.hospital.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hospital.domain.HosBuild;
import com.ruoyi.hospital.service.IHosBuildService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 楼宇信息Controller
 * 
 * @author ruoyi
 * @date 2024-01-06
 */
@RestController
@RequestMapping("/hospital/building")
public class HosBuildController extends BaseController
{
    @Autowired
    private IHosBuildService hosBuildService;

    /**
     * 查询楼宇信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:building:list')")
    @GetMapping("/list")
    public TableDataInfo list(HosBuild hosBuild)
    {
        startPage();
        List<HosBuild> list = hosBuildService.selectHosBuildList(hosBuild);
        return getDataTable(list);
    }

    /**
     * 查询所有楼宇信息 不分页
     * @return
     */
    @PreAuthorize("@ss.hasPermi('hospital:building:list')")
    @GetMapping("listAll")
    public AjaxResult listAll() {
        return AjaxResult.success(hosBuildService.selectHosBuildList(null));
    }

    /**
     * 导出楼宇信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:building:export')")
    @Log(title = "楼宇信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HosBuild hosBuild)
    {
        List<HosBuild> list = hosBuildService.selectHosBuildList(hosBuild);
        ExcelUtil<HosBuild> util = new ExcelUtil<HosBuild>(HosBuild.class);
        util.exportExcel(response, list, "楼宇信息数据");
    }

    /**
     * 获取楼宇信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:building:query')")
    @GetMapping(value = "/{buildId}")
    public AjaxResult getInfo(@PathVariable("buildId") Long buildId)
    {
        return success(hosBuildService.selectHosBuildByBuildId(buildId));
    }

    /**
     * 新增楼宇信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:building:add')")
    @Log(title = "楼宇信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HosBuild hosBuild)
    {
        return toAjax(hosBuildService.insertHosBuild(hosBuild));
    }

    /**
     * 修改楼宇信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:building:edit')")
    @Log(title = "楼宇信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HosBuild hosBuild)
    {
        return toAjax(hosBuildService.updateHosBuild(hosBuild));
    }

    /**
     * 删除楼宇信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:building:remove')")
    @Log(title = "楼宇信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{buildIds}")
    public AjaxResult remove(@PathVariable Long[] buildIds)
    {
        return toAjax(hosBuildService.deleteHosBuildByBuildIds(buildIds));
    }
}
